#include <memory>
#include "log.hpp"
#include "daemon.hpp"
#include "tcp_server.hpp"

using namespace ns_tcpserver;

void usage(std::string proc)
{
    // std::cout << "usage:\n\t" << proc << " serverport" << std::endl;
    logMessage(Fatal,"usage:\n\t %s serverport",proc.c_str());

}

std::string echo(std::string str)
{  
    // std:: cout << "业务处理"  << std:: endl;
    logMessage(Debug,"业务处理");
    return str;
}
int main(int argc, char *argv[])
{
    // std::cout << "hello tcp_server" << std:: endl;
    if (argc != 2)
    {
        usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = atoi(argv[1]);
    std::unique_ptr<tcpServer> tsvr(new tcpServer(echo,port));

    tsvr->initServer();
    Daemon(); // 将服务器守护进程化
    tsvr->start();
    return 0;
}